<%@page import="bean.GuestBookVO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="bean.GuestBookDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>guestBook.jsp</title>
<link rel="stylesheet" href="/TestWeb/css/guestBook.css"/>
<script type="text/javascript" src="./js/guestBook.js"></script>
</head>
<body>
<jsp:useBean id="guestBook" class="bean.GuestBookVO" scope="page"/>
<jsp:setProperty property="*" name="guestBook"/>
	
	<%-- <%
	
	if(session.getAttribute("sessionMid") == null || session.getAttribute("sessionMid").equals("")){
		%><script type="text/javascript">alert("로그인을 해주세요.\n메인 페이지로 이동합니다.");</script> <%
		%><script type="text/javascript">location.href = "index1.jsp"</script> <%
	}
	%> --%>
	
	<%
		request.setCharacterEncoding("utf-8");
	
		GuestBookDTO dto = new GuestBookDTO();
		dto.setVo(guestBook);
		ArrayList<GuestBookVO> list = dto.select();
	%>
	
	<%	
		if(request.getParameter("tmp") != null){
			if(request.getParameter("tmp").equals("0")){
				%><script type="text/javascript">location.href = "index1.jsp?inc=./Community/guestBook.jsp"</script> <%
			}
		}
		
		if(request.getParameter("tmp") != null){
			if(request.getParameter("tmp").equals("1")){
				if(dto.delete()){
					%><script type="text/javascript">location.href = "index1.jsp?inc=./Community/guestBook.jsp"</script> <%
					%><!--<script type="text/javascript">alert("데이터가 정삭적으로 삭제 되었습니다.");</script> --> <%
				}else{
					%><script type="text/javascript">location.href = "index1.jsp?inc=./Community/guestBook.jsp"</script> <%
					%><!--<script type="text/javascript">alert("삭제 중 오류 발생");</script> --> <%
				}
			}
		}
	%>

	<%
		if(request.getParameter("tmp") != null){
			if(request.getParameter("tmp").equals("2")){
				if(dto.insert()){
					%><script type="text/javascript">location.href = "index1.jsp?inc=./Community/guestBook.jsp"</script> <%
					%><!--<script type="text/javascript">alert("입력 되었습니다.");</script>  --> <%
				}else{
					%><script type="text/javascript">alert("입력 실패 했습니다.");</script><%
				}
			}
		}
	%>
	<h1 id="guestBook_title">방 명 록</h1>
	<hr id="guestBook_title_boardLine"/>
	<div align="center">
		<form name="ifrm" method="post">
			<% 
				if(session.getAttribute("sessionMid") == null || session.getAttribute("sessionMid").equals("")){
					%><input type="text" name="guestbook_mid" id="guestbook_mid" value="" size="23" style="display: none;"/> <%
				}else{
					%><input type="text" name="guestbook_mid" id="guestbook_mid" value="<%=session.getAttribute("sessionMid") %>" size="23" style="display: none;"/> <%
				}
			%>
			<input type="text" name="guestbook_contents" id="guestbook_contents" placeholder="한마디를 입력하세요." size="100"/>
			<input type="button" id="guestBook_button" value="입력"/>
		</form>
	</div><p/>
	<div id="allWrap" style="font-size: small;">
		<div id="guestBook_headerTitle" align="center">
				<div id="guestBook_headerTitle_rno">번호</div>
				<div id="guestBook_headerTitle_mid">아이디</div>
				<div id="guestBook_headerTitle_contents">한마디</div>
				<div id="guestBook_headerTitle_date">작성일</div>
				<div id="guestBook_headerTitle_del"></div>
		</div>
		<%for(int i=0; i<list.size(); i++){ 
			GuestBookVO v = list.get(i);
		%>
		<div id="guestBook_contents">
				<div id="guestBook_contents_rno"><%=v.getGuestbook_rno() %></div>
				<div id="guestBook_contents_mid"><%=v.getGuestbook_mid() %></div>
				<div id="guestBook_contents_contents"><%=v.getGuestbook_contents() %></div>
				<div id="guestBook_contents_date"><%=v.getGuestbook_date() %></div>
				<%if(v.getGuestbook_mid().equals( session.getAttribute("sessionMid") )){ %>
					<div id="guestBook_contents_del"><a href="#" onclick="guestBook_Delete(<%=v.getGuestbook_rno() %>, <%=dto.getNowPage() %>)" style="text-decoration: none;">삭제</a></div>
				<%} %>
		</div>
		<%} %><br/>
		<form name="ffrm" method="post" style="padding-left: 480px;">
			<input type="text" name="find" value="<%=guestBook.getFind() %>" placeholder="아이디를 검색하세요."/>
			<input type="button" id="guestBook_findButton" value="검색"/>
		</form><p/>
		<div align="center">
			<%if(dto.getNowPage()==1){ %>
				<font style="font-family: 돋움; font-weight: bold;">[맨처음]</font>
			<%}else{ %>		
				<a href="#" onclick="goPage(1)" style="font-family: 돋움; font-weight: bold;">[맨처음]</a>
			<%} %>
			<%if(dto.getStartPage()==1){ %>
				<font style="font-family: 돋움; font-weight: bold;">[이전]</font>
			<%}else{ %>	
				<a href="#" onclick="goPage(<%=dto.getStartPage()-1 %>)" style="font-family: 돋움; font-weight: bold;">[이전] </a>
			<%} %>
			<%
			int i = 0;
			for(i=dto.getStartPage(); i<=dto.getEndPage(); i++){ %>
				<a href="#" onclick="goPage(<%=i %>)" style="font-family: 돋움; font-weight: bold; margin: 1px;"><%=i %></a>
			<%} %>
			<%if(dto.getTotPage()!=dto.getEndPage()){ %>
				<a href="#" onclick="goPage(<%=i %>)" style="font-family: 돋움; font-weight: bold;">[다음]</a>
			<%}else{ %>
				<font style="font-family: 돋움; font-weight: bold;">[다음]</font>
			<%} %>
			<%if(dto.getTotPage()==dto.getNowPage()){ %>
				<font style="font-family: 돋움; font-weight: bold;">[맨끝]</font>
			<%}else{ %>		
				<a href="#" onclick="goPage(<%=dto.getTotPage() %>)" style="font-family: 돋움; font-weight: bold;">[맨끝]</a>
			<%} %>
		</div>
	</div>
	<p/>
	<hr id="title_boardLine" style="border-color: #0080ff;"/>
	
	<form name="guestBook_frm" method="post">
		<input type="hidden" name="nowPage"/>
		<input type="hidden" name="find"/>
		<input type="hidden" name="guestbook_rno"/>
		<input type="hidden" name="guestbook_mid"/>
		<input type="hidden" name="guestbook_contents"/>
		<input type="hidden" name="guestbook_date"/>
	</form>
</body>
<script type="text/javascript">init();</script>
</html>